package com.tc.quartz.support.service.impl;

import com.alibaba.fastjson.JSON;
import com.tc.quartz.support.bean.JobManagerBean;
import com.tc.quartz.support.service.IJobManagerService;
import com.tc.quartz.support.service.IRecevieMQService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 支持mq触发job
 * @author yongjin.ye
 *
 */
@Service("com.vip.vpal.quartz.support.service.IRecevieMQService")
public class RecevieMQServiceImpl implements IRecevieMQService {

	protected Logger log = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private IJobManagerService jobManagerService;

	@Override
	public void onTriggerJobMessage(byte[] msg) throws Exception {
		log.info("RecevieMQService onTriggerJobMessage Start");
		try {
			String message = new String(msg);
			log.info("onTriggerJobMessage recevie message is : {}", message);
			JobManagerBean jmbean = JSON.parseObject(message, JobManagerBean.class);
			this.jobManagerService.triggerJob(jmbean);
		} catch (Exception e) {
			log.error("RecevieMQService onTriggerJobMessage ERROR", e);
			throw e;
		} finally {
			log.info("RecevieMQService onTriggerJobMessage End");
		}
	}

}
